package com.haier.nengyuan.myapplication;

import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.Window;
import android.view.WindowManager;

/**
 * Created by wy on 2017/8/26.
 */

public abstract class BaseActivity extends FragmentActivity {
    public static final String[][] energyPowers = {
            {"05:20", "49.66"}, {"05:30", "78.63"}, {"05:40", "169.68"}, {"05:50", "235.38"}
            , {"06:00", "301.08"}, {"06:10", "364.19"}, {"06:20", "522.48"}, {"06:30", "589.73"}, {"06:50", "818.39"}
            , {"07:00", "1101.87"}, {"07:10", "1316.04"}, {"07:20", "1503.31"}, {"07:30", "1597.46"}, {"07:40", "1731.96"}, {"07:50", "1856.63"}
            , {"08:00", "1756.79"}, {"08:10", "1869.56"}, {"08:20", "2315.48"}, {"08:30", "2437.57"}, {"08:40", "2547.24"}, {"08:50", "2649.15"}
            , {"09:00", "3374.42"}, {"09:10", "3510.99"}, {"09:20", "3567.89"}, {"09:30", "3537.89"}, {"09:40", "3596.35"}, {"09:50", "3789.82"}
            , {"10:00", "3836.38"}, {"10:10", "3908.28"}, {"10:20", "4091.41"}, {"10:30", "4116.76"}, {"10:40", "4120.38"}, {"10:50", "4137.45"}
            , {"11:00", "4381.11"}, {"11:10", "4299.89"}, {"11:20", "4459.22"}, {"11:30", "4465.43"}, {"11:40", "4388.87"}, {"11:50", "4437.49"}
            , {"12:00", "4431.29"}, {"12:10", "4485.09"}, {"12:20", "4440.60"}, {"12:30", "4399.21"}, {"12:40", "4384.73"}, {"12:50", "4390.94"}
            , {"13:00", "4286.96"}, {"13:10", "4241.43"}, {"13:20", "4054.17"}, {"13:30", "4041.75"}, {"13:40", "3931.05"}, {"13:50", "3848.28"}
            , {"14:00", "3751.02"}, {"14:10", "3620.14"}, {"14:20", "3428.22"}, {"14:30", "3284.41"}, {"14:40", "3159.22"}, {"14:50", "2966.26"}
            , {"15:00", "2595.87"}, {"15:10", "2267.37"}, {"15:20", "2076.49"}, {"15:30", "2002.51"}, {"15:40", "1923.36"}, {"15:50", "1759.89"}
            , {"16:00", "1603.15"}, {"16:10", "1453.64"}, {"16:20", "1145.33"}, {"16:30", "1017.55"}, {"16:40", "857.70"}, {"16:50", "770.79"}
            , {"17:00", "671.47"}, {"17:10", "531.80"}, {"17:20", "444.37"}, {"17:30", "383.33"}, {"17:40", "351.25"}, {"17:50", "206.41"}
            , {"18:00", "122.09"}, {"18:10", "93.12"}, {"18:20", "69.84"}, {"18:30", "35.69"}, {"18:40", "20.18"}, {"18:50", "13.97"}
            , {"19:00", "12.93"}, {"19:10", "13.45"}
    };
    //封装自己，经常作为上下文用
    public BaseActivity mBaseActivity;
    public FragmentManager mFragmentManager;
    public LayoutInflater mLayoutInflater;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mLayoutInflater = this.getLayoutInflater();
        mBaseActivity = this;
        mFragmentManager = this.getSupportFragmentManager();
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager
                .LayoutParams.FLAG_FULLSCREEN);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            //透明状态栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //透明导航栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }

    }

    //对于Fragment的操作
    public void addFragment(int des, BaseFragment fragment) {
        FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
        fragmentTransaction.add(des, fragment, fragment.tag);
        fragmentTransaction.commit();
    }

    public void removeFragment(BaseFragment fragment) {
        FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
        fragmentTransaction.remove(fragment);
        fragmentTransaction.commit();
    }

    public void replaceFragment(int des, BaseFragment fragment) {
        FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
        fragmentTransaction.replace(des, fragment, fragment.tag);
        fragmentTransaction.commit();
    }

    public void hideFragment(BaseFragment fragment) {
        FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
        fragmentTransaction.hide(fragment);
        fragmentTransaction.commit();
    }

    public void showFragment(BaseFragment fragment) {
        FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
        fragmentTransaction.show(fragment);
        fragmentTransaction.commit();
    }
}
